package com.sikadwafastdaisfondturbo.pretloan.adapter

import android.annotation.SuppressLint
import android.graphics.Typeface
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaRecyclerViewAdapter
import com.sikadwafastdaisfondturbo.lib_baseadapter.SikadwaViewHolderHelper
import com.sikadwafastdaisfondturbo.pretloan.R
import org.json.JSONObject

/**
 * Sikadwa
 * @Author wwdeng
 * @CreateTime: 2024/4/24 14:42
 * @Annotation：贷款申请适配器
 */
class CreditApplyDetailsAdapter(recyclerView: RecyclerView?) :
    SikadwaRecyclerViewAdapter<JSONObject>(recyclerView, R.layout.item_credit_apply_detail) {
    override fun setItemChildListener(helper: SikadwaViewHolderHelper, viewType: Int) {
        helper.setItemChildClickListener(R.id.itemLayout) //点击Item
    }

    @SuppressLint("SetTextI18n")
    override fun fillData(helper: SikadwaViewHolderHelper, position: Int, model: JSONObject) {
        val textTitle = helper.getTextView(R.id.textTitle)
        textTitle.text = model.optString("showName")

        val textValue = helper.getTextView(R.id.textValue)
        textValue.text = model.optString("showDetail")
        if (model.has("title") && model.optString("title") == "YES") {
            textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.FF222222))
            textTitle.setTypeface(Typeface.DEFAULT,Typeface.BOLD)
            textValue.setTextColor(ContextCompat.getColor(mContext, R.color.black))
            textValue.setTypeface(Typeface.DEFAULT,Typeface.BOLD)
            helper.setVisibility(R.id.vLine, View.VISIBLE)
        } else {
            textTitle.setTextColor(ContextCompat.getColor(mContext, R.color.FF999999))
            textTitle.setTypeface(Typeface.DEFAULT,Typeface.NORMAL)
            textValue.setTextColor(ContextCompat.getColor(mContext, R.color.FF222222 ))
            textValue.setTypeface(Typeface.DEFAULT,Typeface.NORMAL)

            if (position == itemCount - 1){
                helper.setVisibility(R.id.vLine, View.INVISIBLE)
            } else {
                helper.setVisibility(R.id.vLine, View.GONE)
            }
        }
    }
}